begin tran

create table #temp(org_card_no nvarchar(50), new_card_no nvarchar(50))

insert into #temp select '852000000952','85200010605'
insert into #temp select '852000002519','85200010607'
insert into #temp select '852000004341','85200010606'
insert into #temp select '852000004568','85200010608'
insert into #temp select '852000002600','85200010609'
insert into #temp select '852000004422','85200010610'
insert into #temp select '852000002947','85200010612'
insert into #temp select '852000000648','85200010613'
insert into #temp select '852000002650','85200010622'
insert into #temp select '852000002590','85200010621'
insert into #temp select '852000004411','85200010620'
insert into #temp select '852000004505','85200010618'
insert into #temp select '852000000626','85200010617'
insert into #temp select '852000000587','85200010615'


declare @i int 
select @i = convert(int, var_data) 
from igs_parm with(updlock) where var_name = 'gv_upd_id'

update pos_sales_hdr set vip_no = a.new_card_no
from #temp a 
where pos_sales_hdr.vip_no = a.org_card_no

update pos_vip_tran set vip_no = a.new_card_no
from #temp a 
where pos_vip_tran.vip_no = a.org_card_no 

update pos_vip_info set vip_no = a.new_card_no, upd_id = @i
from #temp a 
where pos_vip_info.vip_no = a.org_card_no and
 not exists(select * from pos_vip_info aa where a.new_card_no = aa.vip_no)

declare @org_card_no nvarchar(20), @new_card_no nvarchar(20)

declare cu cursor for select org_card_no, new_card_no from #temp 
open cu
fetch cu into @org_card_no, @new_card_no
while @@fetch_status =0
begin
	exec sp_pos_recal_vip_pts @org_card_no, @i
	exec sp_pos_recal_vip_pts @new_card_no, @i
fetch cu into @org_card_no, @new_card_no
end
close cu
deallocate cu

drop table #temp

commit  tran